#include <iostream>
#include <opencv2/opencv.hpp>
#include "svm.h"

int main() {
    int featureNum = 400;
    int labelNum = 10;
    svm_node* charac = new svm_node[featureNum];
    cv::Mat test = cv::imread("../data/4/8.jpg");
    cv::cvtColor(test, test, cv::COLOR_BGR2GRAY);
    cv::threshold(test, test, 170, 255, cv::THRESH_BINARY);
    std::cout << test << std::endl;
    test = test.reshape(1, 1);
    std::cout << test.rows << " " << test.cols << std::endl;
    //特征向量归一化
    //normalize(joint, joint, 0, 1, NORM_MINMAX, -1);
    for(unsigned int i=0; i<featureNum; i++) {
        charac[i].index = i+1;
        if(test.at<uchar >(0, i) == 0) {
            charac[i].value = 0;
        }
        else {
            charac[i].value = 1;
        }
        std::cout << charac[i].value << " ";
        if((i+1)%20 == 0) {
            std::cout << " " << std::endl;
        }
    }
    charac[featureNum].index = -1;

    double* prob_estimates = new double[labelNum];
    int* label = new int[labelNum];
    svm_model *svmModel = svm_load_model("../Data1.model");
    double s = svm_predict(svmModel, charac);
    std::cout << s << std::endl;
    svm_get_labels(svmModel, label);
    //label = svmModel->label;
    svm_predict_probability(svmModel, charac, prob_estimates);
    for(unsigned int i=0; i<10; i++) {
        double pj = prob_estimates[label[i]];
        std::cout << pj << std::endl;
    }

    delete[] charac;
    delete[] prob_estimates;

    return 0;
}